4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
15 // INIT.C -- routines to handle TOOLS.INI
18 // Module contains routines to deal with TOOLS.INI file. Functions in TOOLS.LIB
19 // have not been used because NMAKE needs to be small and the overhead is too
29 // arguments: tag pointer to tag name to be searched for
31 // actions: reads tokens from file
32 // whenever it sees a newline, checks the next token
33 // to see if 1st char is opening paren
34 // if no, reads and discards rest of line and
35 // checks next token to see if it's newline or EOF
36 // and if newline loops to check next token . . .
37 // if yes ('[' found), looks on line for tag
38 // if tag found, looks for closing paren
39 // if ']' found, discards rest of line and returns
40 // else keeps looking until end of file or error
42 // returns: if successful, returns TRUE
43 // if tag never found, returns FALSE
50 BOOL endTag
; // TRUE when find [...]
54 for (line
= 0; fgets(buf
, MAXBUF
, file
); ++line
) {
57 for (s
= _tcstok(buf
+1," \t\n");
59 s
= _tcstok(NULL
," \t\n")
68 if (!_tcsicmp(s
,tag
)) {
77 makeError(0, CANT_READ_FILE
);
86 // arguments: where pointer to name of environment variable
87 // containing path to search
88 // name pointer to name of initialization file
89 // tag pointer to name of tag to find in file
91 // actions: looks for file in current directory
92 // if not found, looks in each dir in path (semicolons
93 // separate each path from the next in the string)
94 // if file is found and opened, looks for the given tag
96 // (if ported to xenix, tagOpen() and searchPath()
97 // should probably use access() and not findFirst().)
99 // returns: if file and tag are found, returns pointer to file,
100 // opened for reading and positioned at the line
101 // following the tag line
111 char szPath
[_MAX_PATH
];
113 // Look for 'name' in current directory
114 if (_access(name
, READ
) != 0) {
117 strncpy(szPath
, name
, sizeof(szPath
));
119 if (!(file
= FILEOPEN(szPath
, "rt"))) {
120 makeError(0, CANT_READ_FILE
, szPath
);
124 return(TRUE
); // look for tag in file
127 if (fclose(file
) == EOF
) { // if tag not found, close
128 makeError(0, ERROR_CLOSING_FILE
, szPath
);
131 return(FALSE
); // file and pretend file not found
138 // arguments: p pointer to string of paths to be searched
139 // name name of file being searched for
141 // actions: looks for name in current directory, then each
142 // directory listed in string.
144 // returns: pointer to path spec of file found, else NULL
146 // I don't use _tcstok() here because that modifies the string that it "token-
147 // izes" and we cannot modify the environment-variable string. I'd have to
148 // make a local copy of the whole string, and then make another copy of each
149 // directory to which I concatenate the filename to in order to test for the
157 NMHANDLE
*searchHandle
160 char *s
; // since it's not in use
163 // We use FindFirst() because the dateTime of file matters to us
164 // We don't need it always but then access() probably uses findFirst()
166 if (findFirst(name
, findBuf
, searchHandle
)) { // check current dir first
167 return(makeString(name
));
170 // Check if environment string is NULL. Unnecessary if check is done
171 // elsewhere, but it's more convenient and safer to do it here.
178 while (*p
&& '\"' == *p
) {
179 // Quotes should not be used in search paths. If we find any,
180 // we ignore them. This way we can form the full path and the
181 // filename without quotes and add an enclosing pair of quotes
182 // later, if necessary.
185 if (!*p
|| (*s
= *p
++) == ';') { // found a dir separator
186 if (s
== buf
) { // ignore ; w/out name
191 return(NULL
); // list exhausted ...
194 if (!IsPathSeparator(*(s
-1))) { // append path separator
195 *s
++ = PATH_SEPARATOR_CHAR
;
200 if (_tcspbrk(buf
,"*?")) { // wildcards not allowed
205 _tcscpy(s
, name
); // append file name, zap
207 if (findFirst(buf
, findBuf
, searchHandle
)) {
208 return(makeString(buf
));
211 s
= buf
; // reset ptr to begin of
212 } // buf and check next dir
214 ++s
; // we keep copying chars
215 } // until find ';' or '\0'